<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="jsPost()">jsPost</button>
    <button onclick="axiosPost()">axiosPost</button>
    <button onclick="axiosPostAmend()">axiosPostAmendJsPost</button>
    <!-- 可以去 bootcdn.cn 这个网站上搜网络jQuery和axios-->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.min.js"></script>
    <script>
        /*
        Content-Type: 
        application / x-www- form - urlencoded url编码
        application / json json格式的
        multipart / form - data form - data格式的， 通常用来上传文件的时候使用 */
        /* 
            jquery  -----  默认url编码
            axios   -----  默认json格式
            他们之间可以转换，改变Content-Type的值
        */
        /* jqPost */
        function jsPost() {
            $.ajax({
                type: "post",
                url: "http://127.168.17.30:3000/api/v1/m",
                data: {
                    name: '刘死狗',
                    age: 18,
                    skills: '治疗',
                },
                success: function (response) {
                    console.log(response);
                }
            });
        }
        /* axiosPost */
        function axiosPost() {
            axios.post('http://192.168.17.30:3000/api/v1/m', {
                name: '墨薇荷',
                age: 18,
                skills: '唱歌,打游戏,吃喝玩乐,睡大觉',
            }).then(res => {
                console.log(res);
            });
        }
        /* axiosPost   将其默认的json格式改为url编码 */
        function axiosPostAmend() {
            axios.post('http://192.168.17.30:3000/api/v1/m', "name=张三&age=19", {
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                }
            }).then(res => {
                console.log(res);
            });
        }
    </script>
</body>

</html>